<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>核销推送</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 60px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox ">
                    <div class="label">批次号</div>
                    <div class="field">
                        <input name="batNo" id="batNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox ">
                    <div class="label">银行流水号</div>
                    <div class="field">
                        <input name=bankNo id="bankNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox ">
	                <div class="label">打款日期</div>
	                <div class="field">
	                	<input name="repayDate" id="repayDate" type="text" class="ui-datepicker" value="" ligerui="width: 115">
	                </div>
	            </div>
                
                <div class="fieldBox ">
                    <div class="label">打款金额</div>
                    <div class="field">
                        <input name="repayMoney" id="repayMoney" type="text" class="ui-textbox" value="">
                    </div>
                </div>
	             <div class="fieldBox ">
	                <div class="label">创建时间</div>
	                <div class="field">
	                	<input name="crtTmStart" id="crtTmStart" type="text" class="ui-datepicker" value="" ligerui="width: 115">
	                	至：
	                	<input name="crtTmEnd" id="crtTmEnd" type="text" class="ui-datepicker" value="" ligerui="width: 115">
	                </div>
	            </div>
                
                <div class="fieldBox ">
					<div class="label">状态</div>
					<div class="field">
						<select name="commitType" id="commitType" ligerui="width: 160">
							<option value="" seleted>请选择</option>
							<option value="0">提交失败</option>
							<option value="1">提交成功</option>
						</select>
					</div>
				</div>
                
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null, callback = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/mcr/mcrWriteOffPushDetail/initList.do',
            method: 'get',
            columns: [
            	{ display: '批次号', name: 'batNo', width: 120, enabledSort:true },
            	{ display: '银行流水号', name: 'bankNo', width: 120, enabledSort:true },
            	{ display: '打款日期',  name: 'repayDate', minWidth: 100, align: 'center', enabledSort: false,render:renderDate },
	            { display: '打款金额', name: 'repayMoney', width: 150, enabledSort:true},
	            { display: '还款笔数', name: 'repayNum', width: 150, enabledSort:true},
	            { display: '实收总金额(元)', name: 'repayAmt', width: 150, enabledSort:true},
	            { display: '实收本金(元)', name: 'repayPrincipal', width: 150, enabledSort:true},
	            { display: '实收利息(元)', name: 'repayInterest', width: 150, enabledSort:true},
	            { display: '实收罚息(元)', name: 'repayPenaltyInterest', width: 150, enabledSort:true},
	            { display: '创建时间',  name: 'crtTm', minWidth: 100, align: 'center', enabledSort: false,render:renderDate },
	            { display: '提交时间',  name: 'commitTm', minWidth: 100, align: 'center', enabledSort: false,render:renderDate},
	            { display: '状态', name: 'commitType', width: 150, enabledSort:true,
                    render:function(rowData){
                        if(rowData.commitType=="0"){
                        	var i='<a class="sq-button-hasicon" href="javascript:failReason(';
    	                    i+="'"+rowData.failReason+"'";
    	                    i+=')"><i class="sqBtnIco_4"></i>提交失败</a>';
                       		return i;
                        }else{
                        	return "提交成功";
                        }
                    }
                },
	            
	            getGridOperColumnContent()
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        callback = function () {
            grid.reload();
        };

    });

  //Grid操作列
    function getGridOperColumnContent(){
    	var data = {
                display: '操作',
                isSort: false,
                width: 280,
                render: function (rowdata, rowindex, value){
                	
                	var h='<a class="sq-button-hasicon" href="javascript:executeAgainPushWriteOffConfirmSummar(';
                    	h+="'"+rowdata.batNo+"'";
                    	h+=')"><i class="sqBtnIco_4"></i>重新提交</a>';
                	
                   	var i='<a class="sq-button-hasicon" href="javascript:checkDetails(';
	                    i+="'"+rowdata.repayBatNos+"'";
	                    i+=')"><i class="sqBtnIco_4"></i>查看明细</a>';
	                	var returnStr = i;  
                    if(rowdata.commitType == 0){
                       	returnStr = h + i;
                    }else{
                    	returnStr = i;
                    }    
	                    
                   	return returnStr;
                }
            }
    	return data;
	}
  
  	
  	//查看明细
    function checkDetails(repayBatNos) {
	   	 $.ligerDialog.open({
	            width: 1200,
	            height: 500,
	            title: '明细',
	            url:'<%=path%>/mcr/mcrWriteOffPushDetail/writeOffPushDetailList.do?repayBatNos='+repayBatNos
	        });
	}
  	
    function failReason(failReason) {
    	$.ligerDialog.SQalert({content: failReason, SQ_type: "warring"});
	}
  
    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
    
    //重新提交
    function executeAgainPushWriteOffConfirmSummar(batNo){
    	var ligerForm = liger.get("searchBar");
    	var data = ligerForm.getData();
    	data["batNo"] = batNo;
    	$.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: '<%=path%>/mcr/mcrWriteOffPushDetail/executeAgainPushWriteOffConfirmSummar.do',
            beforeSend: function(){
                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                }else{
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
    }
</script>

</body>
</html>
